package com.qm.console.controller.rest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.qm.console.controller.dto.BaseDO;
import com.qm.console.controller.dto.BaseRsp;
import com.qm.console.controller.dto.ResultEnum;
import com.qm.console.dao.model.*;
import com.qm.console.pubdef.dto.analysis.AnchorAnalysisDTO;
import com.qm.console.pubdef.dto.anchor.*;
import com.qm.console.pubdef.dto.user.PageInfoDTO;
import com.qm.console.service.anchor.AnchorService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import static com.qm.console.utils.EmojiConverterUtil.emojiConvert;

/**
 * @author huzhao
 * @date 2020/06/09
 * @descriptionanchor
 */
@RestController
@RequestMapping("/anchor")
@Api(value = "[ 控制台:主播管理 ]", description = "主播相关API")
public class AnchorController {

    @Autowired
    private AnchorService AnchorService;


//    @RequiresPermissions("anchor:view")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "真人认证", notes = "真人认证列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = false, dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "limit", value = "每页数量", required = false, dataType = "int", paramType = "query",defaultValue = "10"),
            @ApiImplicitParam(name = "gender", value = "性别", required = false, dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "展示类型，0.未审核过的数据，1.已审核过的数据。", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "创建起始时间", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "创建结束时间", required = false, dataType = "string", paramType = "query")
    })
    public BaseDO<PageInfoDTO<LiveVerificationDOWithBLOBs>> listAnchorVerifyAdmin(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                                     @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                                     @RequestParam(value = "userId", required = false) String userId,
                                                     @RequestParam(value = "gender", required = false) String gender,
                                                     @RequestParam(value = "type", required = false) String type,
                                                     @RequestParam(value = "countryCode", required = false) String countryCode,
                                                     @RequestParam(value = "startTime", required = false) String startTime,
                                                     @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = getGeneralParamMap(limit, page, userId, startTime, endTime);
        if (type != null && !type.equals("")){
            paramMap.put("type", type);
        }
        if (gender != null && !gender.equals("")) {
            paramMap.put("gender", gender);
        }
        if (countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if (type != null && (type.equals("2") || type.equals("3"))){
            // 查询数据库中记录的已经审核过的数据
            switch (type) {
                case "2":
                    paramMap.put("status", "1");
                    break;
                case "3":
                    paramMap.put("status", "2");
                    break;
            }
            return AnchorService.listLiveAuditRecord(paramMap);
        }
        else {
            return AnchorService.listAnchorVerifyAdmin(paramMap);
        }
    }

    @GetMapping("/statistic")
    public BaseRsp anchorStatistic(AnchorAnalysisDTO updateDTO){
        return AnchorService.getAnchorStatistic(updateDTO);
    }

    @RequiresPermissions("anchor:change")
    @PutMapping("/verify")
    public BaseRsp AnchorVerifyAdmin(@RequestBody AnchorVerifyAdminDTO updateDTO){
        // 保存真人认证审核记录数据
        LiveVerificationDOWithBLOBs record = updateDTO.getRecord();
        record.setStatus(updateDTO.getStatus());
        record.setNickname(emojiConvert(record.getNickname()));
        AnchorService.saveLiveAuditRecord(record);
        switch (updateDTO.getStatus()){
            case 0: // 真人
                updateDTO.setStatus(1);
                break;
            case 1: // 女神
                updateDTO.setStatus(3);
                break;
            case 2: // 不通过
                updateDTO.setStatus(2);
                break;
        }
        return AnchorService.updateAnchorVerifyAdmin(updateDTO);
    }

    @RequiresPermissions("anchorAvatar:view")
    @ApiOperation(value = "主播头像审核", notes = "新增男女性别筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = false, dataType = "string", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "limit", value = "每页数量", required = false, dataType = "string", paramType = "query",defaultValue = "10"),
            @ApiImplicitParam(name = "userId", value = "被举报ID/举报人ID", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "数据类型 0.未审核，1.已审核", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别0:未知;1:男;2:女", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "identifyType", value = "认证类型 0:未认证;1:真人认证;2:主播认证", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "起始时间", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = false, dataType = "string", paramType = "query")
    })
    @GetMapping("/avatar/list")
    public BaseDO listAnchorAvatarAdmin(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                        @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                        @RequestParam(value = "userId", required = false) String userId,
                                        @RequestParam(value = "countryCode", required = false) String countryCode,
                                        @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                                        @RequestParam(value = "gender", required = false) String gender,
                                        @RequestParam(value = "identifyType", required = false) String identifyType,
                                        @RequestParam(value = "startTime", required = false) String startTime,
                                        @RequestParam(value = "endTime", required = false) String endTime){
        Map paramMap= new HashMap<>();
        paramMap.put("pageSize", limit);
        paramMap.put("pageNum", page);
        if(userId != null){
            paramMap.put("userId", userId);
        }
        if(gender != null){
            paramMap.put("gender", gender);
        }
        if(identifyType != null && !identifyType.equals("")){
            paramMap.put("identifyType", identifyType);
        }
        if(startTime != null){
            paramMap.put("startTime", startTime);
        }
        if(endTime != null){
            paramMap.put("endTime", endTime);
        }
        if(countryCode != null){
            paramMap.put("countryCode", countryCode);
        }
        if(type.equals("0")) {
            return AnchorService.listAnchorAvatarAdmin(paramMap);
        }
        else{
            return AnchorService.listAvatarAuditRecord(paramMap);
        }
    }

    @RequiresPermissions("anchorAvatar:change")
    @PostMapping("/update/official/switch")
    public BaseRsp updateOfficialSwitch(@RequestBody DynamicStateDTO updateDTO){
        return AnchorService.saveDynamicState(updateDTO);
    }

    @RequiresPermissions("anchorAvatar:change")
    @PostMapping("/avatar")
    public BaseRsp verifyAnchorAvatar(@RequestBody AnchorVerifyAvatarAdminDTO updateDTO){
        List<AvatarAuditDO> records = updateDTO.getRecords();
        Integer status = updateDTO.getStatus();
        for(int i=0; i<records.size(); i++){
            AvatarAuditDO item = records.get(i);
            item.setStatus(status);
            item.setNickname(emojiConvert(item.getNickname()));
        }
        AnchorService.saveAvatarAuditRecord(records);
        return AnchorService.updateAnchorAvatarAdmin(updateDTO);
    }

    @RequiresPermissions("anchorPhoto:view")
    @GetMapping("/photos/list")
    public BaseDO listAnchorPhotoVerify(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                         @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                         @RequestParam(value = "userId", required = false) String userId,
                                         @RequestParam(value = "gender", required = false) String gender,
                                         @RequestParam(value = "identifyType", required = false) String identifyType,
                                         @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                                         @RequestParam(value = "countryCode", required = false) String countryCode,
                                         @RequestParam(value = "startTime", required = false) String startTime,
                                         @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(identifyType != null && !identifyType.equals("")){
            paramMap.put("identifyType", identifyType);
        }
        if(gender != null && !gender.equals("")) {
            paramMap.put("gender", gender);
        }
        if(countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if(type.equals("0")) {
            return AnchorService.listAnchorPhotoVerifyAdmin(paramMap);
        }
        else{
            return AnchorService.listPhotosAuditRecord(paramMap);
        }
    }

    @RequiresPermissions("anchorPhoto:change")
    @PostMapping("/photos")
    public BaseRsp verifyAnchorPhoto(@RequestBody AnchorVerifyPhotoAdminDTO updateDTO){
        JSONObject data = (JSONObject) JSONObject.toJSON(updateDTO);

        JSONArray list = data.getJSONArray("userPhotosList");

        for(int i=0; i<list.size(); i++){
            JSONObject item = (JSONObject) JSONObject.toJSON(list.get(i));
            item.getJSONObject("userInfoVo").put("nickname", emojiConvert(item.getJSONObject("userInfoVo").getString("nickname")));
        }

        AnchorService.saveAuditRecord(list);

        return AnchorService.updateAnchorPhotoVerifyAdmin(updateDTO);
    }

    @RequiresPermissions("anchorVideo:view")
    @GetMapping("/video/list")
    public BaseDO listVerifyAnchorVideo(@RequestParam(value = "limit",required = false,defaultValue = "20") String limit,
                                         @RequestParam(value = "page",required = false,defaultValue = "1") String page,
                                         @RequestParam(value = "userId", required = false) String userId,
                                         @RequestParam(value = "identifyType", required = false) String identifyType,
                                         @RequestParam(value = "countryCode", required = false) String countryCode,
                                         @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                                         @RequestParam(value = "startTime", required = false) String startTime,
                                         @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(identifyType != null && !identifyType.equals("")){
            paramMap.put("identifyType", identifyType);
        }
        if(countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if(type.equals("0")){
            return AnchorService.listAnchorVideoVerifyAdmin(paramMap);
        }
        else{
            return AnchorService.listVideoAuditRecord(paramMap);
        }
    }

    @RequiresPermissions("anchorVideo:change")
    @PostMapping("/video")
    public BaseRsp verifyAnchorVideo(@RequestBody AnchorVerifyVideoAdminDTO updateDTO){
        //视频审核数据保存
        List<VideoAuditDO> records = updateDTO.getRecords();
        for (int i=0; i<records.size(); i++) {
            VideoAuditDO item = records.get(i);
            item.setStatus(updateDTO.getStatus());
            item.setNickname(emojiConvert(item.getNickname()));
        }
        AnchorService.saveVideoAuditRecord(records);
        return AnchorService.updateAnchorVideoVerifyAdmin(updateDTO);
    }

    @RequiresPermissions("anchorCover:view")
    @GetMapping("/cover/list")
    public BaseDO listAnchorCoverImage(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                       @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                       @RequestParam(value = "userId", required = false) String userId,
                                       @RequestParam(value = "countryCode", required = false) String countryCode,
                                       @RequestParam(value = "identifyType", required = false) String identifyType,
                                       @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                                       @RequestParam(value = "startTime", required = false) String startTime,
                                       @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(identifyType != null && !identifyType.equals("")){
            paramMap.put("identifyType", identifyType);
        }
        if(countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if(type.equals("1")){
            return AnchorService.listBackgroundAuditRecord(paramMap);
        }
        else{
            return AnchorService.listAnchorCoverImageAdmin(paramMap);
        }
    }

    @RequiresPermissions("anchorCover:change")
    @PostMapping("/cover")
    public BaseRsp verifyAnchorCoverImage(@RequestBody AnchorVerifyCoverImageDTO updateDTO){
        // 封面审核数据保存
        List<BackgroundAuditDO> records = updateDTO.getRecords();
        for (int i=0; i<records.size(); i++) {
            BackgroundAuditDO item = records.get(i);
            item.setStatus(updateDTO.getStatus());
            item.setNickname(emojiConvert(item.getNickname()));
        }
        AnchorService.saveBackgroundAuditRecord(records);
        return AnchorService.updateAnchorCoverVerifyAdmin(updateDTO);
    }

    @RequiresPermissions("screenShot:view")
    @GetMapping("/video/thumbs")
    public BaseRsp listVideoThumb(VideoRecordQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of(
                "list", AnchorService.listVideoThumb(queryDTO), "count", AnchorService.countVideoThumb(queryDTO)
                ));
    }

    @RequiresPermissions("screenShot:view")
    @GetMapping("/video/thumb/all")
    public BaseRsp listVideoThumbAll(ScreenShotQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS,
                ImmutableMap.of("list", AnchorService.listVideoThumbAll(queryDTO),
                        "count", AnchorService.countVideoThumbAll(queryDTO),
                        "uids", AnchorService.listVideoThumbUser(queryDTO)));
    }

    @RequiresPermissions("screenShot:delete")
    @GetMapping("/video/thumb/delete")
    public BaseRsp deleteImage(@RequestParam("id") String id) {
        AnchorService.deleteVideoThumb(id);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequiresPermissions(("screenShot:update"))
    @GetMapping("/video/thumb/verify")
    public BaseRsp verifyChat(@RequestParam("ids") String ids) {
        List<String> chatIds = Arrays.asList(ids.split(","));
        AnchorService.verifyChat(chatIds);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequiresPermissions(("screenShot:update"))
    @GetMapping("/video/user/verify")
    public BaseRsp verifyUserChat(@RequestParam("userId") String userId) {
        AnchorService.verifyUserChat(userId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequiresPermissions("immsg:view")
    @GetMapping("/immsgs")
    public BaseRsp listIMMsgs(ImMsgQueryDTO queryDTO) {
        return AnchorService.listIMMsgs(queryDTO);
    }

    @GetMapping("/immsgs/session")
    public BaseRsp sessionMsg(ImMsgQueryDTO queryDTO) {
        return AnchorService.sessionMsg(queryDTO);
    }

    @RequiresPermissions("immsg:view")
    @GetMapping("/imMsg/reversionRate")
    public BaseRsp imMsgReversionRate(ImMsgQueryDTO queryDTO) {
        return AnchorService.reversionRate(queryDTO);
    }
    @RequiresPermissions("immsg:update")
    @GetMapping("/immsgs/verify")
    public BaseRsp verifyIMMsg(ImMsgUpdateDTO queryDTO) {
        AnchorService.verifyIMMsg(queryDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
    @RequiresPermissions("immsg:delete")
    @GetMapping("/immsgs/delete")
    public BaseRsp deleteIMMsg(ImMsgUpdateDTO queryDTO) {
        AnchorService.deleteIMMsg(queryDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

//    @RequiresPermissions("goddess:view")
    @GetMapping("/goddess/list")
    public BaseRsp listGoddess(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                       @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                       @RequestParam(value = "userId", required = false) String userId,
                                       @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                                       @RequestParam(value = "startTime", required = false) String startTime,
                                       @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(type.equals("1")){
            return AnchorService.listGoddessRecord(paramMap);
        }
        else{
            return AnchorService.listGoddess(paramMap);
        }
    }

//    @RequiresPermissions("goddess:change")
    @PutMapping("/goddess")
    public BaseRsp updateGoddess(@RequestBody GoddessDTO goddessDTO){
        // 保存真人认证审核记录数据
        GoddessAuditDOWithBLOBs record = goddessDTO.getRecord();
        record.setStatus(goddessDTO.getStatus());
        record.setNickname(emojiConvert(record.getNickname()));
        AnchorService.saveGoddessRecord(record);

        return AnchorService.updateGoddess(goddessDTO);
    }

    //    @RequiresPermissions("comment:view")
    @GetMapping("/comment/list")
    public BaseRsp listComment(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                               @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                               @RequestParam(value = "userId", required = false) String userId,
                               @RequestParam(value = "postId", required = false) String postId,
                               @RequestParam(value = "gender", required = false) String gender,
                               @RequestParam(value = "countryCode", required = false) String countryCode,
                               @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                               @RequestParam(value = "startTime", required = false) String startTime,
                               @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap= getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(postId != null && !postId.equals("")){
            paramMap.put("postId", postId);
        }
        if(gender != null && !gender.equals("")){
            paramMap.put("gender", gender);
        }
        if(type != null && !type.equals("")){
            paramMap.put("status", type);
        }
        if(countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if(type == null || type.equals("0") || type.equals("3")){
            return AnchorService.listComments(paramMap);
        }
        else{
            return AnchorService.listCommentRecords(paramMap);
        }
    }

    //    @RequiresPermissions("comment:delete")
    @DeleteMapping("/comment/delete")
    public BaseRsp deleteComment(@RequestBody CommentAuditDOWithBLOBs commentAuditDOWithBLOBs){
        // 保存真人认证审核记录数据
        commentAuditDOWithBLOBs.setNickname(emojiConvert(commentAuditDOWithBLOBs.getNickname()));
        commentAuditDOWithBLOBs.setComment(emojiConvert(commentAuditDOWithBLOBs.getComment()));
        commentAuditDOWithBLOBs.setStatus(1);
        AnchorService.saveCommentRecord(commentAuditDOWithBLOBs);

        return AnchorService.deleteComment(commentAuditDOWithBLOBs);
    }

    @PostMapping("/comment/handle")
    public BaseRsp handleComment(@RequestBody CommentAuditDOWithBLOBs commentAuditDOWithBLOBs){
        // 保存真人认证审核记录数据
        commentAuditDOWithBLOBs.setNickname(emojiConvert(commentAuditDOWithBLOBs.getNickname()));
        commentAuditDOWithBLOBs.setComment(emojiConvert(commentAuditDOWithBLOBs.getComment()));
        commentAuditDOWithBLOBs.setStatus(2);
        AnchorService.saveCommentRecord(commentAuditDOWithBLOBs);

        return new BaseRsp(ResultEnum.SUCCESS);
    }

    //    @RequiresPermissions("post:view")
    @GetMapping("/post/list")
    public BaseRsp listPost(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                               @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                               @RequestParam(value = "userId", required = false) String userId,
                               @RequestParam(value = "gender", required = false) String gender,
                               @RequestParam(value = "topicName", required = false) String topicName,
                               @RequestParam(value = "deleteFlag", required = false) String deleteFlag,
                               @RequestParam(value = "isLiveCertification", required = false) String isLiveCertification,
                               @RequestParam(value = "isPrivate", required = false) String isPrivate,
                               @RequestParam(value = "countryCode", required = false) String countryCode,
                               @RequestParam(value = "isRecommend", required=false) String isRecommend,
                               @RequestParam(value = "type", required = false, defaultValue = "0") String type,
                               @RequestParam(value = "startTime", required = false) String startTime,
                               @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap= getGeneralParamMap(limit, page, userId, startTime, endTime);
        if(gender != null && !gender.equals("")){
            paramMap.put("gender", gender);
        }
        if(isLiveCertification != null && !isLiveCertification.equals("")){
            paramMap.put("isLiveCertification", isLiveCertification);
        }
        if(topicName != null && !topicName.equals("")){
            paramMap.put("topicName", topicName);
        }
        if(type != null && !type.equals("")){
            paramMap.put("status", type);
        }
        if(type != null && !type.equals("")){
            paramMap.put("isPrivate", isPrivate);
        }
        if(countryCode != null && !countryCode.equals("")){
            paramMap.put("countryCode", countryCode);
        }
        if (!StringUtils.isEmpty(isRecommend)) {
            paramMap.put("isRecommend", isRecommend);
        }

        if (!StringUtils.isEmpty(deleteFlag)) {
            paramMap.put("deleteFlag", deleteFlag);
        }

        if (type != null && type.equals("2")){
            paramMap.put("isReview", "true");
        }

        if (type != null && type.equals("3")){
            paramMap.put("isReview", "false");
        }
        return AnchorService.listPosts(paramMap);
    }

    @GetMapping("/post/detail")
    public BaseRsp postDetail(@RequestBody @RequestParam(value = "contentId", required = false, defaultValue = "20") String contentId){
        // 获取动态详情
        Map<String, String> paramMap= new HashMap<>();
        paramMap.put("contentId", contentId);
        return AnchorService.postDetail(paramMap);
    }

    //    @RequiresPermissions("post:delete")
    @DeleteMapping("/post/delete")
    public BaseRsp deletePost(@RequestBody PostAuditDOWithBLOBs postAuditDOWithBLOBs){
        // 保存真人认证审核记录数据
        postAuditDOWithBLOBs.setNickname(emojiConvert(postAuditDOWithBLOBs.getNickname()));
        postAuditDOWithBLOBs.setContent(emojiConvert(postAuditDOWithBLOBs.getContent()));
        postAuditDOWithBLOBs.setStatus(1);
        AnchorService.savePostRecord(postAuditDOWithBLOBs);

        return AnchorService.deletePost(postAuditDOWithBLOBs);
    }

    @PostMapping("/post/handle")
    public BaseRsp handlePost(@RequestBody PostAuditDOWithBLOBs postAuditDOWithBLOBs){
        // 保存真人认证审核记录数据
        postAuditDOWithBLOBs.setNickname(emojiConvert(postAuditDOWithBLOBs.getNickname()));
        postAuditDOWithBLOBs.setContent(emojiConvert(postAuditDOWithBLOBs.getContent()));
//        postAuditDOWithBLOBs.setCreateTimestamp(postAuditDOWithBLOBs.getCreateTimestamp());
        postAuditDOWithBLOBs.setStatus(2);
        AnchorService.savePostRecord(postAuditDOWithBLOBs);

        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping("/checkFamily")
    public BaseRsp checkFamily(@RequestBody CheckFamilyDO checkFamilyDO){
        AnchorService.saveCheckFamily(checkFamilyDO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @GetMapping("/checkFamily/list")
    public BaseRsp getFamilyList(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") String page,
                                 @RequestParam(value = "familyId", required = false) Integer familyId,
                                 @RequestParam(value = "applyUserId", required = false) Integer applyUserId,
                                 @RequestParam(value = "type", required = false, defaultValue = "0") Integer type,
                                 @RequestParam(value = "checkType", required = false) Integer checkType,
                                 @RequestParam(value = "startTime", required = false) String startTime,
                                 @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, Object> paramMap= new HashMap<>();
        paramMap.put("pageSize", limit);
        paramMap.put("pageNum", page);
        paramMap.put("type", type);
        if(familyId != null){
            paramMap.put("familyId", familyId);
        }
        if(applyUserId != null){
            paramMap.put("applyUserId", applyUserId);
        }
        if(startTime != null && !startTime.equals("")){
            paramMap.put("startTime", startTime);
        }
        if(endTime != null && !endTime.equals("")){
            paramMap.put("endTime", endTime);
        }
        if(checkType != null){
            paramMap.put("checkType", checkType.toString());
        }
        return AnchorService.getFamilyList(paramMap);
    }


    private Map<String, String> getGeneralParamMap(String limit, String page, String userId, String startTime, String endTime){
        Map<String, String> paramMap= new HashMap<>();
        paramMap.put("pageSize", limit);
        paramMap.put("pageNum", page);
        if(userId != null && !userId.equals("")){
            paramMap.put("userId", userId);
        }
        if(startTime != null && !startTime.equals("")){
            paramMap.put("startTime", startTime);
        }
        if(endTime != null && !endTime.equals("")){
            paramMap.put("endTime", endTime);
        }
        return paramMap;
    }

}
